<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>js循环结构之for</title>
  <style>
    span {
      color: #fff;
    }
  </style>
</head>
<body>
  <script>
    function star(row = 5) {
      for (let i = 0; i < row; i++) {
        for (let j = 0; j <= i; j++) {
          document.write('*')
        }
        document.write('<br/>')
      }
    }
    star()
    star(20)
    // 杨辉三角
    function triangle(row = 5) {
      for (let i = 1; i < row; i++) {
        for (let j = row - i; j > 0; j--) {
          document.write('<span>*</span>')
        }
        for (let k = i * 2 - 1; k > 0; k--) {
          document.write('*')
        }
        document.write('<br/>')
      }
    }
    triangle()
    triangle(20)
  </script>
</body>
</html>